<%@page import="service.Link"%>
<%@page import="service.PutCache"%>
<%@page import="model.NewsRecent"%>
<%@page import="java.util.ArrayList"%>
<%@page import="javax.cache.CacheException"%>
<%@page import="java.util.Collections"%>
<%@page import="javax.cache.CacheManager"%>
<%@page import="javax.cache.Cache"%>
<%@page import="service.Util"%>
<%@page import="model.Tags"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.Format"%>
<%@page import="model.News"%>
<%@page import="com.googlecode.objectify.Query"%>
<%
	response.setCharacterEncoding("utf-8");
	Format formatter = new SimpleDateFormat("dd-MM-yyyy h:m:s");
	
	ArrayList<String> newTag = PutCache.getCacheList("newTag");
	
	ArrayList<NewsRecent> newRecent = PutCache.getCacheNews("newRecent");
	
	ArrayList<Query<News>> listCate = (ArrayList<Query<News>>) request.getAttribute("listCate");
	

	String title = "Tìm kiếm";
	String description = "Tìm kiếm tin tức thuộc cùng từ khóa ";
	String keyword = ",tin tức,tin hót,tin mới nhất,tổng hợp tin";
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html; charset=utf-8");
%>
<%@ page language="java" import="java.util.Enumeration"
	pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<jsp:include page="layout/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
	<jsp:param name="description" value="<%=description %>" />
	<jsp:param name="keywords" value="<%=keyword %>" />
</jsp:include>

<div class="body">
	<div class="body-left">
		<form action="/gsearch" id="cse-main-search-box">
	<input type="hidden" name="cx"
		value="<%=Link.getCx() %>" /> <input type="hidden"
		name="cof" value="FORID:10" /> <input type="hidden" name="ie"
		value="UTF-8" /> <input id="cse-main-search-text" type="text"
		name="q" autocomplete="on" class="input_search" style="width:450px;"/> <input type="submit" name="sa"
		value="Search" />
</form>
<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript">
	google.load('search', '1');
	google.setOnLoadCallback(function() {
		google.search.CustomSearchControl.attachAutoCompletionWithOptions(
				'013315504628135767172:d6shbtxu-uo+qptype:1', document
						.getElementById('cse-main-search-text'),
				'cse-main-search-box', {
					'styleOptions' : {
						'widthOffset' : 150
					}
				});
	});
</script>
<style type="text/css">
	#cse-main-search-results iframe {
    height: 1400px;
    width: 500px;
}
#cse-main-search-text{
width: 350px !important;
}
.gs-webResult{
width: auto;
}
</style>
<div id="cse-main-search-results"></div>
<script type="text/javascript">
	var googleSearchIframeName = "cse-main-search-results";
	var googleSearchFormName = "cse-main-search-box";
	var googleSearchFrameWidth = 728;
	var googleSearchDomain = "www.google.com";
	var googleSearchPath = "/cse";
</script>
<script type="text/javascript"
	src="http://www.google.com/afsonline/show_afs_search.js"></script>
	</div>
	<div class="body-right">
		<ul class="mostview clearfix">
			<li class="head">Xem Mới nhất</li>
			<%
			if(newRecent.size()>0)
			{
				for(int i=0;i<newRecent.size();i++)
				{
			%>
				<li>
					<a class="avatar" href="/<%=Link.linkDetail() %>/<%=Util.convertAlias(newRecent.get(i).getTitle())%>">
						<img alt="<%=Util.cleanString(newRecent.get(i).getTitle()) %>" src="<%=newRecent.get(i).getThumb()%>">
					</a>
					<h3>
						<a href="/<%=Link.linkDetail() %>/<%=Util.convertAlias(newRecent.get(i).getTitle())%>"><%=newRecent.get(i).getTitle() %></a>
					</h3> <span><%=formatter.format(newRecent.get(i).getDate()) %></span></li>
			<%
				}
			}
			%>
		</ul>
		<div class="focus">
			<%
			if(listCate.size()>0)
			{
				for(int i=0;i<listCate.size();i++)
				{
					if(i%2==0)
					{
			%>
					<div class="focus-left fl">
						<%
						int j=0;
						for(News news:listCate.get(i))
						{
							if(j==0)
							{
						%>
								<h6>
									<a href="/<%=Link.linkCate() %>/<%=news.getCategoryAlias()%>"><%=news.getCategory() %></a>
								</h6>
								<div class="clearfix">
									<a class="avatar" href="/<%=Link.linkDetail() %>/<%=news.getAlias()%>">
										<img alt="<%=Util.cleanString(news.getTitle().getValue()) %>" src="<%=news.getThumb()%>">
									</a>
									<h3>
										<a href="/<%=Link.linkDetail() %>/<%=news.getAlias()%>"><%=news.getTitle().getValue() %></a>
									</h3>
								</div>
								<ul>
							<%
							} else {
							%>
							
								<li><a href="/<%=Link.linkDetail() %>/<%=news.getAlias()%>"><%=news.getTitle().getValue() %></a></li>
							<%
							}
							j++;
						}
						%>
						</ul>
					</div>
					<%
					} else {
					%>
						<div class="focus-right fr">
							<%
							int j=0;
							for(News news:listCate.get(i))
							{
								if(j==0)
								{
							%>
							<h6>
								<a href="/<%=Link.linkCate() %>/<%=news.getCategoryAlias()%>"><%=news.getCategory() %></a>
							</h6>
							<div class="clearfix">
								<a class="avatar" href="/<%=Link.linkDetail() %>/<%=news.getAlias()%>">
										<img alt="<%=Util.cleanString(news.getTitle().getValue()) %>" src="<%=news.getThumb()%>">
								</a>
								<h3>
									<a href="/<%=Link.linkDetail() %>/<%=news.getAlias()%>"><%=news.getTitle().getValue() %></a>
								</h3>
								<span><%=formatter.format(news.getDate()) %></span>
							</div>
							<p>- <%=Util.cutDescription(news.getContent().getValue()) %></p>
							<ul>
							<%
							} else {
							%>
								<li><a href="/<%=Link.linkDetail() %>/<%=news.getAlias()%>"><%=news.getTitle().getValue() %></a></li>
							<%
							}
							j++;
						}
						%>
						</ul>
					</div>
					<div class="clear"></div>
		<%
					}
				}
			}
		%>
			<div class="clear"></div>
		</div>

		<div class="cloudtags">
			<span>Có thể bạn quan tâm</span>
			<ul class="clearfix">
				<%
				if(newTag.size()>0)
				{
					for(int i=0;i<newTag.size();i++)
					{
				%>
						<li><a href="/<%=Link.linkTag() %>/<%=Util.convertAlias(newTag.get(i))%>"> <%=newTag.get(i) %> </a></li>
				<%
					}
				}
				%>
			</ul>
		</div>
	</div>
	<div class="clear"></div>
</div>

<jsp:include page="layout/footer.jsp"></jsp:include>